<template>
    <div>
        <div class="outmain ba_f heighthv pad_20 bor_rad5">
            <div class="shuju_title mar_b20">
                <div class="shuju_title_text">
                    <span>系统颜色</span>
                </div>
            </div>
            <el-form ref="form" :model="form" label-width="180px" class="mar_t20">
                <el-form-item label="系统主题色">
                    <div class="flex">
                        <el-color-picker v-model="form.color"></el-color-picker>
                        <div class="colorValue mar_l10 wei">{{form.color}}</div>
                    </div>
                </el-form-item>
            </el-form>
        </div>
        <div class="mar_t20 ba_f pad_20 t_c">
            <el-button type="primary" @click="submitForm">保存</el-button>
        </div>
    </div>
</template>
<script>
    import {getConfig, postConfig} from "@/api/setup";

    export default {
        created() {
            this.bus.$emit('loading', true);
            this.init();
        },
        data() {
            return {
                form: {
                    color: '#409EFF',
                }
            }
        },
        methods: {
            async init() {
                const {data} = await getConfig({ident: 'style'});
                this.form2 = this.form
                this.form = Object.assign(this.form2, data);
                this.bus.$emit('loading', false)
            },
            submitForm() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        this.form.ident = 'style'
                        this.form.identName = '风格设置'
                        const {msg} = await postConfig(this.form);
                        this.$baseMessage(msg, "success");
                        this.init();
                    } else {
                        return false;
                    }
                });
            },
        }
    }
</script>
<style lang="scss" scoped>
    .colorValue {
        display: inline-block;
        height: 40px;
        line-height: 40px;
    }
</style>
